﻿using BS.Domain.RBAC;
using BS.Infra;
using BS.Write.Api.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace BS.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private readonly BaseDbContext _dbContext;

        private readonly SmsClientFactory _smsClientFactory;
        public TestController(BaseDbContext dbContext, SmsClientFactory smsClientFactory)
        {
            _dbContext = dbContext;
            _smsClientFactory = smsClientFactory;
        }


        [HttpPost]
        public void Add()
        {
            var user = new UserInfo
            {
                UserName = "Test"
            };
            _dbContext.UserInfo.Add(user);
            _dbContext.SaveChanges();

        }

        [HttpPost("{id}")]
        public void Update(int id)
        {
            var user = _dbContext.UserInfo.Find(id);
            user.UserName = "Test Updated";
            _dbContext.SaveChanges();
        }

        [HttpPost("{id}")]
        public void Delete(int id)
        {
            var user = _dbContext.UserInfo.Find(id);
            _dbContext.UserInfo.Remove(user);
            _dbContext.SaveChanges();
        }

        [HttpGet]
        public void SendSms()
        {
            _smsClientFactory.SendSms("15901026041","{\"code\":\"1234\"}", "阿里云短信测试", "SMS_154950909");
        }
    }
}
